/*================================================================
*   
*   文件名称：main.cpp
*   创 建 者：yq
*   创建日期：2023年02月19日
*   描    述：还原 二阶魔方
*   	目前只做了 u l f 三种，不过完全够用
*
================================================================*/

#include <iostream>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

const int FACE = 4;
const int COLOR = 6;
const int CNT = 6;
const int ALL = FACE * COLOR;

string cube;
string st;


queue<string> status;
queue<string> step;
unordered_set<string> vis;

const string STEP = "udlrfb";

string u(string& cube) {
	char t = cube[0];
	cube[0] = cube[2];
	cube[2] = cube[3];
	cube[3] = cube[1];
	cube[1] = t;
	string tmp = cube.substr(16, 2);
	cube[16] = cube[12];
	cube[17] = cube[13];
	cube[12] = cube[20];
	cube[13] = cube[21];
	cube[20] = cube[8];
	cube[21] = cube[9];
	cube[8] = tmp[0];
	cube[9] = tmp[1];
	return cube;
}

string d(string& cube) {
	return cube;
}

string l(string& cube) {
	char t = cube[8];
	cube[8] = cube[10];
	cube[10] = cube[11];
	cube[11] = cube[9];
	cube[9] = t;
	string tmp = string(1, cube[16]) + cube[18];
	cube[16] = cube[0];
	cube[18] = cube[2];
	cube[0] = cube[23];
	cube[2] = cube[21];
	cube[23] = cube[4];
	cube[21] = cube[6];
	cube[4] = tmp[0];
	cube[6] = tmp[1];

	return cube;
}

string r(string& cube) {
	return cube;
}

string f(string& cube) {
	char t = cube[16];
	cube[16] = cube[18];
	cube[18] = cube[19];
	cube[19] = cube[17];
	cube[17] = t;
	string tmp = cube.substr(2, 2);
	cube[2] = cube[11];
	cube[3] = cube[9];
	cube[11] = cube[5];
	cube[9] = cube[4];
	cube[5] = cube[12];
	cube[4] = cube[14];
	cube[12] = tmp[0];
	cube[14] = tmp[1];

	return cube;
}

string b(string& cube) {
	return cube;
}

string fc(int i) {
	string c = cube;
	switch (i) {
	case 0:
		c = u(c);
		break;
	case 1:
		c = d(c);
		break;
	case 2:
		c = l(c);
		break;
	case 3:
		c = r(c);
		break;
	case 4:
		c = f(c);
		break;
	case 5:
		c = b(c);
		break;
	}
	return c;
}


bool isok(const string& cube) {
	char cur;
	for (int i = 0; i < ALL; ++ i) {
		if (i % FACE == 0) cur = cube[i];
		else if (cur != cube[i]) return false;
	}
	return true;
}

bool inputok() {
	unordered_map<char,int> m;
	for (char c: cube) {
		++ m[c];
	}
	for (auto [k, v]: m) {
		if (v != FACE) return false;
	}
	
	return m.size() == COLOR;
}

int main() {

	// 进行输入
	do {
		cin >> cube;
	} while (!inputok());

	cout << "input is ok\n";


	// 如果一开始就ok
	bool ok = isok(cube);
	if (ok) {
		cout << " ok \n" ;
		return  0;
	}
	

	// 进入队列
	status.push(cube);
	step.push(st);
	vis.insert(cube);

	// cube'
	string t;

	string ans;

	// BFS
	while (status.size() && !ok) {

		cube = status.front();
		st = step.front();
		status.pop();	step.pop();

		for (int i = 0; i < CNT / 2; ++ i) {
			// operate
			t = fc(i * 2);

			// 检测
			if (isok(t)) {
				ans = st + STEP[i * 2];
				ok = true;
				break;
			}
			if (vis.count(t)) continue;
			
			vis.insert(t);
			status.push(t);
			step.push(st + STEP[i * 2]);
		} // for
			
	}	// while

	// no ans
	if (ans.empty()) {
		cout << "NO" << endl;
		return 0;
	}

	// 处理 ans
	int n = ans.length();
	string re;

	for (int i = 0; i < n; ++ i) {
	 	if ((i != 0 && i != n-1) && ans[i] == ans[i + 1] && ans[i] == ans[i - 1]) {
	 		re +=  "'"	;
			++ i;
		} else {
			re += string{" "} + ans[i];
		}
	}

	cout << "the ans is : \n";
	cout << re << endl;

	return 0;
}	// main()
